<?php
class Application_Model_Addresses extends Zend_Db_Table{
	protected $_name = 'addresses';

	public function saveAddress( $data ){
		try {
			if (isset($data['id']) && $data['id'] > 0) {
				if($res = $this->find((int)$data['id'])) {
					$row = $res->current();
					unset($data['id']);
					$row->setFromArray($data);
					$row->save();
					return $row->id;
				}
				else {
					return false;
				}
			}
			else {
				$this->insert($data);
				$lastId = $this->getAdapter()->lastInsertId();
				return $lastId;
			}
		}
		catch(Zend_Exception $e) {
			return false;
		}
	}

}